package top.raxidin.user.service.imple;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import top.raxidin.user.entity.User;
import top.raxidin.user.mapper.UserMapper;
import top.raxidin.user.service.UserService;



@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserMapper userMapper;


    @Override
    public User login(User param) {
        User user = userMapper.getUser(param);
        if(user!=null){
            BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
            boolean matches = passwordEncoder.matches(param.getPassword(), user.getPassword());
            if(matches){
                return user;
            }
        }
        return null;
    }
}
